import App from './App'
import Vue from 'vue'

// vuex数据管理中心
import store from '@/store'
Vue.prototype.$store = store;

// 引入全局uView
import uView from '@/uni_modules/uview-ui'
Vue.use(uView)

// 公共组件
import publicModule from "@/components/public-module.vue";
Vue.component("public-module", publicModule);

// request
import '@/config/request.js';

// 地址白名单
const whiteList = [
  '/pages/index/index', '/pages/mine/index',
  '/pages/papers/components/detail', '/pages/post/index',
   '/pages/papers/index','/pages/teachercomment/index'
]

// 检查地址白名单
const checkWhite = (url) => {
  const path = url.split('?')[0]
  return whiteList.indexOf(path) !== -1
}

// 页面跳转验证拦截器,是否需要登录判断
uni.addInterceptor("navigateTo", {
  invoke(to) {
    if (store.state.token) {
      return true
    } else {
      if (checkWhite(to.url)) {
        return true
      }
      store.commit("setLoginShow", true);
      return false
    }
  }
})

Vue.config.productionTip = false
App.mpType = 'app'

const app = new Vue({
  ...App
})

app.$mount()